package org.siqisource.webstart.usemanagement.controller;

import java.util.List;

import org.siqisource.webstart.core.utils.condition.SimpleCondition;
import org.siqisource.webstart.core.widgets.grid.model.GridData;
import org.siqisource.webstart.usemanagement.helper.UserHelper;
import org.siqisource.webstart.usemanagement.model.User;
import org.siqisource.webstart.usemanagement.model.UserCtrl;
import org.siqisource.webstart.usemanagement.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {

	@Autowired
	UserService userService;

	@RequestMapping("/usermanagement/UserController/doGridData.do")
	@ResponseBody
	public GridData<User> doGridData(User user, UserCtrl ctrl, Model model) {
		SimpleCondition condition = UserHelper.getQueryCondition(ctrl);
		List<User> dataList = userService.listPage(condition, ctrl.getRowBounds());

		GridData<User> gridData = new GridData<User>();
		gridData.setRows(dataList);
		gridData.setTotal(userService.count(condition));
		return gridData;
	}
	
	
	@RequestMapping("/usermanagement/UserController/doList.do")
	public String doList(User user, UserCtrl ctrl, Model model) {
		return "/usermanagement/userList";
	}
	
	@RequestMapping("/usermanagement/UserController/doNew.do")
	public String doNew(User user, UserCtrl ctrl, Model model) {
		return "/usermanagement/userNew";
	}
	
	@RequestMapping("/usermanagement/UserController/doSaveNew.do")
	@ResponseBody
	public String doSaveNew(User user, UserCtrl ctrl, Model model) {
		System.out.println(user.getUsername());
		System.out.println(user.getPassword());
		return "/usermanagement/userNew";
	}
}
